import time

from chaojiying.chaojiying import Chaojiying_Client
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

option = Options()
option.add_argument('--disable-blink-features=AutomationControlled')


if __name__ == '__main__':
    chrome = Chrome(options=option)
    chrome.get("https://auditsecdr.group.cpic.com")
    chrome.maximize_window()

    time.sleep(2)
    chrome.find_element(By.XPATH, '//*[@id="details-button"]').click()
    chrome.find_element(By.XPATH, '//*[@id="proceed-link"]').click()

    time.sleep(2)
    chrome.find_element(By.XPATH, '//*[@id="username"]').send_keys('c_zhanglixiang-003')
    chrome.find_element(By.XPATH, '//*[@id="password"]').send_keys('20211201@Ghxl')

    chrome.find_element(By.XPATH, '//*[@id="captcha_image"]').screenshot("anxin.png")

    chaojiying = Chaojiying_Client('17511617323', '123456', '96001')
    im = open('anxin.png', 'rb').read()
    img_result = chaojiying.PostPic(im, 1902)
    imgNum = img_result['pic_str']
    print(imgNum)

    chrome.find_element(By.XPATH, '//*[@id="captcha"]').send_keys(imgNum)

    chrome.find_element(By.XPATH, '//*[@id="sendLoginMsg"]').click()

    code = input("短信验证码：")

    chrome.find_element(By.XPATH, '//*[@id="messageCode"]').send_keys(code)

    chrome.find_element(By.XPATH, '/html/body/div/div[1]/div[2]/div[2]/div/section/div[2]/button[1]').click()

    time.sleep(4)

    # 管理下拉按钮 //*[@id="sidebar-menu-ul"]/li[7]/a/span
    chrome.find_element(By.XPATH, '//*[@id="sidebar-menu-ul"]/li[7]/a/span').click()
    time.sleep(3)

    # above = chrome.find_element(By.XPATH, '//*[@id="menu_ops"]/a')
    # ActionChains(chrome).move_to_element(above).perform()

    # 运维管理选项
    chrome.find_element(By.XPATH, '//*[@id="menu_ops"]/a').click()
    time.sleep(2)

    # putty连接弹框
    chrome.find_element(By.XPATH, '//*[@id="ops"]/div[1]/div/div[2]/div[1]/span[1]/span/span[1]/span[1]').click()
    time.sleep(1)

    # //*[@id="account_login_username"]
    chrome.find_element(By.XPATH, '//*[@id="account_login_username"]').send_keys('tomcat')
    chrome.find_element(By.XPATH, '//*[@id="account_login"]/div/div/div[2]/form/div/div[2]/div/div/input').send_keys(
        'Csdmx@2017')
    chrome.find_element(By.XPATH, '//*[@id="account_login"]/div/div/div[2]/div/button[1]').click()

    time.sleep(18000)

